/*    */ package cn.zzuisa.news.servlet;
/*    */ 
/*    */ import cn.zzuisa.news.DTO.CommentDTO;
/*    */ import cn.zzuisa.news.convertor.Comment2CommentDTO;
/*    */ import cn.zzuisa.news.entity.Comment;
/*    */ import cn.zzuisa.news.enums.CommonEnums;
/*    */ import cn.zzuisa.news.form.CommentForm;
/*    */ import cn.zzuisa.news.service.CommentService;
/*    */ import cn.zzuisa.news.service.impl.CommentServiceImpl;
/*    */ import cn.zzuisa.news.util.JsonUtil;
/*    */ import cn.zzuisa.news.util.ResultVOUtil;
/*    */ import com.google.gson.Gson;
/*    */ import java.io.IOException;
/*    */ import java.util.List;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.annotation.WebServlet;
/*    */ import javax.servlet.http.HttpServlet;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ @WebServlet(name = "comment", urlPatterns = {"/comment"}, asyncSupported = true)
/*    */ public class CommontServlet
/*    */   extends HttpServlet
/*    */ {
/* 36 */   private CommentService commentServiceImpl = new CommentServiceImpl();
/*    */ 
/*    */ 
/*    */   
/*    */   protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
/* 41 */     String method = req.getParameter("method");
/* 42 */     if (method.equals("add")) {
/* 43 */       String json = JsonUtil.getStrResponse(req);
/* 44 */       CommentForm commentForm = (CommentForm)(new Gson()).fromJson(json, CommentForm.class);
/* 45 */       CommentForm comment = null;
/* 46 */       comment = this.commentServiceImpl.add(commentForm);
/* 47 */       List<Comment> comments = this.commentServiceImpl.list(commentForm.getNewsId());
/* 48 */       List<CommentDTO> commentDTOs = Comment2CommentDTO.convert(comments);
/* 49 */       if (comment != null) {
/* 50 */         resp.getWriter().println(JsonUtil.setData(ResultVOUtil.success(commentDTOs)));
/*    */       } else {
/* 52 */         resp.getWriter().println(JsonUtil.setData(ResultVOUtil.failed(CommonEnums.PARAM_ERROR)));
/*    */       } 
/*    */     } 
/*    */   }
/*    */ }


/* Location:              /Users/frank/Desktop/admin/WEB-INF/classes/!/cn/zzuisa/news/servlet/CommontServlet.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */